﻿using System.Windows.Forms;

namespace game
{
    public partial class UserControlpiano : UserControl
    {
        public UserControlpiano()
        {
            InitializeComponent();

            InitSound();
        }

        private void InitSound()
        {
            string path = Application.StartupPath + "\\Sounds\\";

            mediaPlayer = new common.MediaPlayer(path, axCL2, axDL2, axEL2, axFL2, axGL2, axAL2, axBL2, axCL1, axDL1, axEL1, axFL1, axGL1, axAL1, axBL1, axC, axD, axE, axF, axG, axA, axB, axCH1, axDH1, axEH1, axFH1, axGH1, axAH1, axBH1, axCH2, axDH2, axEH2, axFH2, axGH2, axAH2, axBH2, axCH3, axDH3, axEH3);

            for (int i = 0; i < 38; i++)
            {
                mediaPlayer.GetSound(i, i);
            }
        }

        private common.MediaPlayer mediaPlayer;

        private void UserControlpiano_KeyDown(object sender, KeyEventArgs e)
        {
        }

        private void UserControlpiano_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            var e = keyData;
            int i1 = 0;
            int i2 = 7;
            int i3 = 14;
            int i4 = 21;
            switch (e)
            {
                case Keys.D1:
                    this.mediaPlayer.axWindowsMediaPlayers[i1 + 0].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i1 + 0].Ctlcontrols.play();
                    break;

                case Keys.D2:
                    this.mediaPlayer.axWindowsMediaPlayers[i1 + 1].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i1 + 1].Ctlcontrols.play();
                    break;

                case Keys.D3:
                    this.mediaPlayer.axWindowsMediaPlayers[i1 + 2].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i1 + 2].Ctlcontrols.play();
                    break;

                case Keys.D4:
                    this.mediaPlayer.axWindowsMediaPlayers[i1 + 3].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i1 + 3].Ctlcontrols.play();
                    break;

                case Keys.D7:
                    this.mediaPlayer.axWindowsMediaPlayers[i1 + 4].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i1 + 4].Ctlcontrols.play();
                    break;

                case Keys.D8:
                    this.mediaPlayer.axWindowsMediaPlayers[i1 + 5].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i1 + 5].Ctlcontrols.play();
                    break;

                case Keys.D9:
                    this.mediaPlayer.axWindowsMediaPlayers[i1 + 6].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i1 + 6].Ctlcontrols.play();
                    break;

                ///
                case Keys.Q:
                    this.mediaPlayer.axWindowsMediaPlayers[i2 + 0].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i2 + 0].Ctlcontrols.play();
                    break;

                case Keys.W:
                    this.mediaPlayer.axWindowsMediaPlayers[i2 + 1].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i2 + 1].Ctlcontrols.play();
                    break;

                case Keys.E:
                    this.mediaPlayer.axWindowsMediaPlayers[i2 + 2].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i2 + 2].Ctlcontrols.play();
                    break;

                case Keys.R:
                    this.mediaPlayer.axWindowsMediaPlayers[i2 + 3].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i2 + 3].Ctlcontrols.play();
                    break;

                case Keys.U:
                    this.mediaPlayer.axWindowsMediaPlayers[i2 + 4].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i2 + 4].Ctlcontrols.play();
                    break;

                case Keys.I:
                    this.mediaPlayer.axWindowsMediaPlayers[i2 + 5].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i2 + 5].Ctlcontrols.play();
                    break;

                case Keys.O:
                    this.mediaPlayer.axWindowsMediaPlayers[i2 + 6].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i2 + 6].Ctlcontrols.play();
                    break;

                ///

                case Keys.A:
                    this.mediaPlayer.axWindowsMediaPlayers[i3 + 0].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i3 + 0].Ctlcontrols.play();
                    break;

                case Keys.S:
                    this.mediaPlayer.axWindowsMediaPlayers[i3 + 1].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i3 + 1].Ctlcontrols.play();
                    break;

                case Keys.D:
                    this.mediaPlayer.axWindowsMediaPlayers[i3 + 2].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i3 + 2].Ctlcontrols.play();
                    break;

                case Keys.F:
                    this.mediaPlayer.axWindowsMediaPlayers[i3 + 3].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i3 + 3].Ctlcontrols.play();
                    break;

                case Keys.J:
                    this.mediaPlayer.axWindowsMediaPlayers[i3 + 4].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i3 + 4].Ctlcontrols.play();
                    break;

                case Keys.K:
                    this.mediaPlayer.axWindowsMediaPlayers[i3 + 5].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i3 + 5].Ctlcontrols.play();
                    break;

                case Keys.L:
                    this.mediaPlayer.axWindowsMediaPlayers[i3 + 6].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i3 + 6].Ctlcontrols.play();
                    break;

                ///
                case Keys.Z:
                    this.mediaPlayer.axWindowsMediaPlayers[i4 + 0].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i4 + 0].Ctlcontrols.play();
                    break;

                case Keys.X:
                    this.mediaPlayer.axWindowsMediaPlayers[i4 + 1].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i4 + 1].Ctlcontrols.play();
                    break;

                case Keys.C:
                    this.mediaPlayer.axWindowsMediaPlayers[i4 + 2].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i4 + 2].Ctlcontrols.play();
                    break;

                case Keys.V:
                    this.mediaPlayer.axWindowsMediaPlayers[i4 + 3].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i4 + 3].Ctlcontrols.play();
                    break;

                case Keys.M:
                    this.mediaPlayer.axWindowsMediaPlayers[i4 + 4].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i4 + 4].Ctlcontrols.play();
                    break;

                case Keys.Oemcomma:
                    this.mediaPlayer.axWindowsMediaPlayers[i4 + 5].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i4 + 5].Ctlcontrols.play();
                    break;

                case Keys.OemPeriod:
                    this.mediaPlayer.axWindowsMediaPlayers[i4 + 6].Ctlcontrols.stop();
                    this.mediaPlayer.axWindowsMediaPlayers[i4 + 6].Ctlcontrols.play();
                    break;

                default:
                    break;
                    ///
                    //case Keys.D1:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i1 + 0].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i1 + 0].Ctlcontrols.play();
                    //    break;

                    //case Keys.D2:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i1 + 1].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i1 + 1].Ctlcontrols.play();
                    //    break;

                    //case Keys.D3:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i1 + 2].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i1 + 2].Ctlcontrols.play();
                    //    break;

                    //case Keys.D4:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i1 + 3].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i1 + 3].Ctlcontrols.play();
                    //    break;

                    //case Keys.D5:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i1 + 4].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i1 + 4].Ctlcontrols.play();
                    //    break;

                    //case Keys.D6:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i1 + 5].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i1 + 5].Ctlcontrols.play();
                    //    break;

                    //case Keys.D7:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i1 + 6].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i1 + 6].Ctlcontrols.play();
                    //    break;

                    /////
                    ////case Keys.D8:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i2 + 0].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i2 + 0].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.D9:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i2 + 1].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i2 + 1].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.D0:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i2 + 2].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i2 + 2].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.Subtract:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i2 + 3].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i2 + 3].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.Add:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i2 + 4].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i2 + 4].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.Back:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i2 + 5].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i2 + 5].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.O:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i2 + 6].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i2 + 6].Ctlcontrols.play();
                    ////    break;

                    //case Keys.Q:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i2 + 0].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i2 + 0].Ctlcontrols.play();
                    //    break;

                    //case Keys.W:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i2 + 1].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i2 + 1].Ctlcontrols.play();
                    //    break;

                    //case Keys.E:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i2 + 2].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i2 + 2].Ctlcontrols.play();
                    //    break;

                    //case Keys.R:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i2 + 3].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i2 + 3].Ctlcontrols.play();
                    //    break;

                    //case Keys.T:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i2 + 4].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i2 + 4].Ctlcontrols.play();
                    //    break;

                    //case Keys.Y:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i2 + 5].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i2 + 5].Ctlcontrols.play();
                    //    break;

                    //case Keys.U:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i2 + 6].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i2 + 6].Ctlcontrols.play();
                    //    break;

                    /////

                    //case Keys.D0:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i3 + 0].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i3 + 0].Ctlcontrols.play();
                    //    break;

                    //case Keys.OemMinus:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i3 + 1].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i3 + 1].Ctlcontrols.play();
                    //    break;

                    //case Keys.Oemplus:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i3 + 2].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i3 + 2].Ctlcontrols.play();
                    //    break;

                    //case Keys.Back:

                    //    this.mediaPlayer.axWindowsMediaPlayers[i3 + 3].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i3 + 3].Ctlcontrols.play();
                    //    break;

                    //case Keys.Insert:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i3 + 4].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i3 + 4].Ctlcontrols.play();
                    //    break;

                    //case Keys.Home:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i3 + 5].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i3 + 5].Ctlcontrols.play();
                    //    break;

                    //case Keys.PageUp:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i3 + 6].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i3 + 6].Ctlcontrols.play();
                    //    break;

                    ////case Keys.A:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i3 + 0].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i3 + 0].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.S:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i3 + 1].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i3 + 1].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.D:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i3 + 2].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i3 + 2].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.F:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i3 + 3].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i3 + 3].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.J:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i3 + 4].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i3 + 4].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.K:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i3 + 5].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i3 + 5].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.L:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i3 + 6].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i3 + 6].Ctlcontrols.play();
                    ////    break;

                    //case Keys.P:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i4 + 0].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i4 + 0].Ctlcontrols.play();
                    //    break;

                    //case Keys.OemOpenBrackets:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i4 + 1].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i4 + 1].Ctlcontrols.play();
                    //    break;

                    //case Keys.OemCloseBrackets:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i4 + 2].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i4 + 2].Ctlcontrols.play();
                    //    break;

                    //case Keys.Enter:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i4 + 3].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i4 + 3].Ctlcontrols.play();
                    //    break;

                    //case Keys.Delete:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i4 + 4].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i4 + 4].Ctlcontrols.play();
                    //    break;

                    //case Keys.End:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i4 + 5].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i4 + 5].Ctlcontrols.play();
                    //    break;

                    //case Keys.PageDown:
                    //    this.mediaPlayer.axWindowsMediaPlayers[i4 + 6].Ctlcontrols.stop();
                    //    this.mediaPlayer.axWindowsMediaPlayers[i4 + 6].Ctlcontrols.play();
                    //    break;
                    /////
                    ////case Keys.Z:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i4 + 0].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i4 + 0].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.X:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i4 + 1].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i4 + 1].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.C:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i4 + 2].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i4 + 2].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.V:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i4 + 3].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i4 + 3].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.M:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i4 + 4].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i4 + 4].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.Oemcomma:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i4 + 5].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i4 + 5].Ctlcontrols.play();
                    ////    break;

                    ////case Keys.OemPeriod:
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i4 + 6].Ctlcontrols.stop();
                    ////    this.mediaPlayer.axWindowsMediaPlayers[i4 + 6].Ctlcontrols.play();
                    ////    break;

                    //default:
                    //    break;
            }

            if (e == Keys.Space)
            {
                foreach (var item in this.mediaPlayer.axWindowsMediaPlayers)
                {
                    item.Ctlcontrols.stop();
                }
            }

            return base.ProcessDialogKey(keyData);
        }

        private void panel_b_Paint(object sender, PaintEventArgs e)
        {
        }

        private void panel_c_Paint(object sender, PaintEventArgs e)
        {
        }
    }
}